.TH std::reverse_iterator::operator*,-> 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::reverse_iterator::operator*,-> \- std::reverse_iterator::operator*,->

.SH Synopsis
   reference operator*() const;                             \fI(until C++17)\fP
   constexpr reference operator*() const;                   \fI(since C++17)\fP
   pointer operator->() const;                                            \fI(until C++17)\fP
   constexpr pointer operator->() const;                                  \fI(since C++17)\fP
                                                                          \fI(until C++20)\fP
   constexpr pointer operator->() const             \fB(1)\fP
                                                        \fB(2)\fP
       requires (std::is_pointer_v<Iter> ||                               \fI(since C++20)\fP

                 requires (const Iter i) {
   i.operator->(); });

   Returns a reference or pointer to the element previous to current.

   1) Equivalent to Iter tmp = current; return *--tmp;.

   2) Equivalent to return std::addressof(operator*());.                  \fI(until C++20)\fP
   2) Equivalent to return current - 1; if Iter is a pointer type.        \fI(since C++20)\fP
   Otherwise, equivalent to return std::prev(current).operator->();.

.SH Parameters

   \fI(none)\fP

.SH Return value

   Reference or pointer to the element previous to current.

.SH Example


// Run this code

 #include <complex>
 #include <iostream>
 #include <iterator>
 #include <vector>

 int main()
 {
     using RI0 = std::reverse_iterator<int*>;
     int a[]{0, 1, 2, 3};
     RI0 r0{std::rbegin(a)};
     std::cout << "*r0 = " << *r0 << '\\n';
     *r0 = 42;
     std::cout << "a[3] = " << a[3] << '\\n';

     using RI1 = std::reverse_iterator<std::vector<int>::iterator>;
     std::vector<int> vi{0, 1, 2, 3};
     RI1 r1{vi.rend() - 2};
     std::cout << "*r1 = " << *r1 << '\\n';

     using RI2 = std::reverse_iterator<std::vector<std::complex<double>>::iterator>;
     std::vector<std::complex<double>> vc{{1,2}, {3,4}, {5,6}, {7,8}};
     RI2 r2{vc.rbegin() + 1};
     std::cout << "vc[2] = (" << r2->real() << ',' << r2->imag() << ")\\n";
 }

.SH Output:

 *r0 = 3
 a[3] = 42
 *r1 = 1
 vc[2] = (5,6)

.SH See also

   operator[] accesses an element by index
              \fI(public member function)\fP
